package sdk.service;

import java.text.SimpleDateFormat;
import java.util.Date;

import dao.ResumeDAO;
import dao.impl.DeptDAOImpl;
import dao.impl.DutyDAOImpl;
import dao.impl.EducationDAOImpl;
import dao.impl.EmpDAOImpl;
import dao.impl.ResumeDAOImpl;

import model.Emp;
import model.Resume;
import util.Page;

public class ResumeManagerService {
	ResumeDAO resumeDAO=new ResumeDAOImpl();
	public Page<Resume>getByTime(int pageNo,int pageSize,Date starttime,Date endtime){
		return resumeDAO.getByTime(pageNo, pageSize, starttime, endtime);
	}
	public boolean addResume(int empid,String deptname,String dutyname,String eduname,String workcont,double score,String st,String et){
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
		
		Resume resume=new Resume();
		resume.setEmp(new EmpDAOImpl().getEmpById(empid));
		resume.setDept(new DeptDAOImpl().getDeptByName(deptname));
		resume.setDuty(new DutyDAOImpl().getDutyByName(dutyname));
		resume.setEducation(new EducationDAOImpl().getByName(eduname));
		resume.setWorkcontent(workcont);
		resume.setScore(score);
		
		try {
			resume.setStarttime(sdf.parse(st));
			resume.setEndtime(sdf.parse(et));
		} catch (Exception e) {
		}
		return resumeDAO.addResume(resume);
	}
	public boolean deleteById(int id){
		return resumeDAO.deleteById(id);
	}
	public boolean deleteByEmp(Emp emp){
		return resumeDAO.deleteByEmp(emp);
	}
	public boolean updateResume(int id,int empid,String deptname,String dutyname,String eduname,String workcont,double score,String st,String et){
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");

		Resume resume=new Resume();
		resume.setId(id);
		resume.setEmp(new EmpDAOImpl().getEmpById(empid));
		resume.setDept(new DeptDAOImpl().getDeptByName(deptname));
		resume.setDuty(new DutyDAOImpl().getDutyByName(dutyname));
		resume.setEducation(new EducationDAOImpl().getByName(eduname));
		resume.setWorkcontent(workcont);
		resume.setScore(score);

		try {
			resume.setStarttime(sdf.parse(st));
			resume.setEndtime(sdf.parse(et));
		} catch (Exception e) {
		}
		return resumeDAO.updateResume(resume);
	}
	public Page<Resume> getAllResume(int pageNo, int pageSize){
		return resumeDAO.getAllResume(pageNo, pageSize);
	}
	public Page<Resume>getByType(int pageNo,int pageSize,Object object){
		return resumeDAO.getByType(pageNo, pageSize, object);
	}
}
